import unittest
from transapp.TransApp import TransApp
from transapp.TransViewIF import TransView


class MockView(TransView):

    def initTransformer(self, transList):
        self._trans = transList
        self._oriString = ""

    def getAllTransLen(self):
        return len(self._trans)

    def getSelectedTransLen(self):
        return len(self._selectedTrans)

    def refreshSelectedTrans(self, transList):
        self._selectedTrans = transList

    def getResultString(self):
        return self._resultString

    def getOriString(self):
        return self._oriString

    def setOriString(self, oriString):
        self._oriString = oriString

    def showResultString(self, result):
        self._resultString = result


class Test(unittest.TestCase):

    def setUp(self):
        self.transApp = TransApp(["Upper", "Lower", "TrimPrefix"])
        self.gui = MockView()
        self.transApp.setView(self.gui)

    def tearDown(self):
        pass

    def testInit(self):
        self.assertEqual(3, self.gui.getAllTransLen())

    def testAdd(self):
        self.transApp.addTrans("Upper")
        self.assertEqual(1, self.gui.getSelectedTransLen())

    def testRemove(self):
        self.transApp.addTrans("Upper")
        self.transApp.addTrans("Lower")
        self.assertEqual(2, self.gui.getSelectedTransLen())
        self.transApp.removeTrans("Upper")
        self.assertEqual(1, self.gui.getSelectedTransLen())

    def testRemoveAll(self):
        self.transApp.addTrans("Upper")
        self.transApp.addTrans("Lower")
        self.transApp.removeAllTrans()
        self.assertEqual(0, self.gui.getSelectedTransLen())

    def testApply(self):
        self.transApp.addTrans("Upper")
        self.gui.setOriString("hello")
        self.transApp.applyTransform()
        self.assertEqual("HELLO", self.gui.getResultString())


if __name__ == "__main__":
    # import sys;sys.argv = ['', 'Test.testInit']
    unittest.main()
